<?php
/**
 * Created by PhpStorm.
 * User: dev
 * Date: 4/9/14
 * Time: 1:07 PM
 */

class Admin_Login_Controller extends Admin_Controller {

	public $restful = true;

	public function __construct()
	{
		parent::__construct();
		//--Your Code --//
		$this->theme->set_theme("admin") ;
		$this->theme->set_layout("login") ;

	}


	public function get_index(){

		$this->theme->title("Login");
		return $this->theme->render('admin::login');
	}
	
	public function post_index(){


		$rules = array(
				'email' => 'required|email',
				'password' => 'required',
		);


		$validator = Validator::make(Input::get(), $rules);
		if( $validator->fails() )
		{
			return Redirect::back()->with_input()->with_errors($validator)->with('message','Invalid Operation !');
		}else{

			$credentials = array(
					'username' => Input::get('email'),
					'password' => Input::get('password'),
			);

			if(Auth::attempt($credentials, true)){

			//	print Auth::user()->email;
	
				if(Auth::user()->role_id == '1'){
						$users =DB::table('users')
					->where('id', '=', Auth::user()->id)
					->update(array(
				
							'updated_at' => date('m/d/Y h:i:s a', time()),
					)
					);
						
					return Redirect::to("admin/home");
				}else{
					
					
					return Redirect::back()->with('message','Invalid Input !');
					
				}
				//redirect back to homepage
				
			}else{
				return Redirect::back()->with('message','Invalid Input !');
				
			}
		}
	}
	
	public function get_signout(){
		
		Auth::logout();
		
		
		return Redirect::to('admin/login');
	}


}